package com.wenc.psi.dao;

import androidx.lifecycle.LiveData;

import com.wenc.psi.pojo.SaleDetail;
import com.wenc.psi.utils.JDBCUtils;

import java.sql.SQLException;
import java.util.List;

public class SaleDetailDao extends JDBCUtils implements Dao<SaleDetail> {
    @Override
    public void insert(SaleDetail... saleDetails) {
        try {
            conn = getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            for (int i = 0; i < saleDetails.length; i++) {
                String sql = "INSERT INTO saledetail VALUES('"
                        + saleDetails[i].getSaleId() + "','"
                        + saleDetails[i].getSerialNumber() + "','"
                        + saleDetails[i].getPartId() + "','"
                        + saleDetails[i].getPrice() + "','"
                        + saleDetails[i].getQuantity() + "')";
                stmt.executeUpdate(sql);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            close(stmt, conn);
        }
    }

    @Override
    public void delete(SaleDetail... saleDetails) {

    }

    @Override
    public void delete(String... ids) {

    }

    @Override
    public void update(SaleDetail oldT, SaleDetail newT) {

    }

    @Override
    public List<SaleDetail> getAllData() {
        return null;
    }

    @Override
    public SaleDetail getDataById(String id) {
        return null;
    }

    @Override
    public LiveData<List<SaleDetail>> getAllLiveData() {
        return null;
    }
}
